<template>
  <el-form
    ref="formRef"
    :model="formData"
    :rules="formRules"
    v-loading="formLoading"
    label-width="0px"
    :inline-message="true"
    :disabled="disabled"
  >
    <el-table :data="formData" class="-mt-10px">
      <el-table-column label="序号" type="index" align="center" width="60" />
      <el-table-column label="产品名称" min-width="180">
        <template #default="{ row }">
          <el-form-item class="mb-0px!">
            <el-input disabled v-model="row.productName" />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column label="规格" min-width="150">
        <template #default="{ row }">
          <el-form-item class="mb-0px!">
            <el-input disabled v-model="row.productStandards" />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column label="生产批次" min-width="100">
        <template #default="{ row }">
          <el-form-item class="mb-0px!">
            <el-input disabled v-model="row.productBatch" />
          </el-form-item>
        </template>
      </el-table-column>
      <!-- <el-table-column label="入库批次" min-width="100">
        <template #default="{ row }">
          <el-form-item class="mb-0px!">
            <el-input disabled v-model="row.inboundBatch" />
          </el-form-item>
        </template>
      </el-table-column> -->
      <el-table-column label="单位" min-width="80">
        <template #default="{ row }">
          <el-form-item class="mb-0px!">
            <el-input disabled v-model="row.productUnitName" />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column label="账面库存" min-width="100">
        <template #default="{ row }">
          <el-form-item class="mb-0px!">
            <el-input disabled v-model="row.stockCount" :formatter="erpCountInputFormatter2" />
          </el-form-item>
        </template>
      </el-table-column>
  
      <el-table-column label="实际库存" min-width="100">
        <template #default="{ row }">
          <el-form-item class="mb-0px!">
            <el-input disabled v-model="row.actualCount" :formatter="erpCountInputFormatter2" />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column label="盈亏数量" min-width="100">
        <template #default="{ row }">
          <el-form-item class="mb-0px!">
            <el-input disabled v-model="row.rowcount" :formatter="erpCountInputFormatter2" />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column label="有效期" min-width="180">
        <template #default="{ row }">
          <el-form-item class="mb-0px!">
            <el-date-picker type="datetime" disabled v-model="row.productValidityDate" />
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column align="center" fixed="right" label="备注" min-width="150">
        <template #default="{ row, $index }">
          <el-form-item :prop="`${$index}.remark`" class="mb-0px!">
            <el-input  disabled v-model="row.remark"  />
          </el-form-item>
        </template>
      </el-table-column>
    </el-table>
  </el-form>
</template>
<script setup lang="ts">
import { StockCheckApi } from '@/api/spd/hospitaloffice/stockcheck'

const props = defineProps<{
  items: undefined
  disabled: false
}>()
const formLoading = ref(false) // 表单的加载中
const formData = ref([])
const formRules = reactive({
  inId: [{ required: true, message: '盘点编号不能为空', trigger: 'blur' }],
  deptId: [{ required: true, message: '仓库名字不能为空', trigger: 'blur' }],
  productId: [{ required: true, message: '产品不能为空', trigger: 'blur' }],
  count: [{ required: true, message: '产品数量不能为空', trigger: 'blur' }]
})
const formRef = ref([]) // 表单 Ref
var deptId2: undefined
onMounted(() => {
  const Info = JSON.parse(localStorage.getItem('user') || '{}');
  const userInfo = JSON.parse(Info.v)
  deptId2 = userInfo.user.deptId
  
});

/** 初始化设置盘点项 */
watch(
  () => props.items,
  async (val) => {
    formData.value = val
  },
  { immediate: true }
)

const erpCountInputFormatter2 = (val) => {
  return Math.round(val);
}

/** 表单校验 */
const validate = () => {
  return formRef.value.validate()
}
defineExpose({ validate })

/** 初始化 */
onMounted(async () => {
})
</script>
